﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using PccCommonForC;

public partial class Manager_DistributionCompany_AddDistributionCompany : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["AdminUserID"] == null)
        {
            Response.Write("<script language=javascript>alert('Time is out.');window.open('../Default.aspx','_top');</script>");
            return;
        }
        if (!IsPostBack)
        {
            BinData();         
        }  
    }

    private void BinData()
    {
        PccMsg msg = new PccMsg();
        if (Request.QueryString["DisCompID"] != "" && Request.QueryString["DisCompID"] != null)
        {
            msg.CreateFirstNode("DisCompID", Request.QueryString["DisCompID"]);
            clsWebShop cls = new clsWebShop();
            DataTable dt = null;
            dt = cls.Get_DistributionCompanyByCondition(msg.GetXmlStr).Tables[0];

            if (dt.Rows.Count > 0)
            {
                txtName.Text = dt.Rows[0]["Name"].ToString();
                txtAddr.Text = dt.Rows[0]["Address"].ToString();
                txtTaxNo.Text = dt.Rows[0]["TaxNo"].ToString();
                txtPhone.Text = dt.Rows[0]["Phone"].ToString().Trim();
                txtEmail.Text = dt.Rows[0]["Email"].ToString();
                txtNote.Text = dt.Rows[0]["Note"].ToString();
            }
        }

    }
    
    
    protected void btnCancel_Click(object sender, EventArgs e)
    {
        ReturnPage();
    }

    private string QueryStringStr(string str)
    {
        return str + "=" + Request.QueryString[str];

    }
    private void ReturnPage()
    {
        Response.Redirect("DistributionCompany.aspx?CodeID=" + Request.QueryString["CodeID"] );
    }
      
    
    protected void btnSave_Click(object sender, EventArgs e)
    {
        clsWebShop cls = new clsWebShop();
        PccMsg msg = new PccMsg();
        string DisCompID = "0";
        if (Request.QueryString["DisCompID"] != "" && Request.QueryString["DisCompID"] != null)
        {
            DisCompID = Request.QueryString["DisCompID"];
        }

        msg.CreateFirstNode("DisCompID", DisCompID);
        msg.CreateFirstNode("Name", txtName.Text);
        msg.CreateFirstNode("Address", txtAddr.Text);
        msg.CreateFirstNode("TaxNo", txtTaxNo.Text);
        msg.CreateFirstNode("Phone", txtPhone.Text);
        msg.CreateFirstNode("Email", txtEmail.Text);
        msg.CreateFirstNode("Note", txtNote.Text);
        msg.CreateFirstNode("UserID", Session["AdminUserID"].ToString());
        string strXML = cls.Ins_Upd_DistributionCompany(msg.GetXmlStr.ToString());
        ReturnPage();
    }
}
